package com.style.study.mp.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.style.study.mp.mapper.UserMapper;
import com.style.study.mp.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserMapper userMapper;

    @RequestMapping("/list")
    public Object list() {
        List<User> list = userMapper.selectPage(
                new Page<User>(1, 10),
                new EntityWrapper<User>().eq("age","2"));
        return list;
    }
    @RequestMapping("/add")
    public void add(){
//        for(int i=0;i<=20;i++){
            User user =new User();
            user.setName("Tom");
            user.setAge(2);
            userMapper.insert(user);
//        }

    }
    @RequestMapping("/all")
    public Object all() {
        List<User> list = userMapper.selectList(null);

        return list;
    }
}
